package cn.cycleif.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum ObjectTypeEnum implements IEnum<Integer> {
  QUESTION(0, "提问", "question"),
  TAG(1, "标签", "tag"),
  ANSWER(2, "回答", "answer"),
  COMMENT(3, "评论", "comment"),
  ;

  private final int    code;
  private final String desc;
  @JsonValue
  private final String sign;

  ObjectTypeEnum(int code, String desc, String sign) {
    this.code = code;
    this.desc = desc;
    this.sign = sign;
  }

  public static ObjectTypeEnum fromCode(Integer code) {
    for (ObjectTypeEnum typeEnum : ObjectTypeEnum.values()) {
      if (typeEnum.getValue()
                  .equals(code)) {
        return typeEnum;
      }
    }
    return null;
  }

  @Override
  public Integer getValue() {
    return this.code;
  }
}
